package com.xinghou.platform.server.api.bussiness.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.main.ReportInfoDAO;
import com.xinghou.platform.dao.main.ReportReasonsConfigDAO;
import com.xinghou.platform.dao.main.ReportSharedCardDAO;
import com.xinghou.platform.dao.main.ReportStoreDAO;
import com.xinghou.platform.entity.req.ReportErrorReq;
import com.xinghou.platform.entity.resp.ReportErrorInfo;
import com.xinghou.platform.model.main.ReportInfo;
import com.xinghou.platform.model.main.ReportReasonsConfig;
import com.xinghou.platform.model.main.ReportSharedCard;
import com.xinghou.platform.model.main.ReportStore;
import com.xinghou.platform.server.api.bussiness.ReportErrorInfoBusinessService;


@Service("reportErrorInfoService")
public class ReportErrorInfoBusinessServiceImpl implements ReportErrorInfoBusinessService {

	@Resource
	private ReportReasonsConfigDAO reportReasonsConfigDAO;
	
	@Resource
	private ReportSharedCardDAO reportSharedCardDAO;
	
	@Resource
	private ReportStoreDAO reportStoreDAO;
	
	@Resource
	private ReportInfoDAO reportInfoDAO;
	
	private List<ReportReasonsConfig> reportReasonsConfigs = new ArrayList<ReportReasonsConfig>();
	
	@Override
	public List<ReportErrorInfo> getReportErrorConfigInfoList(String type) {
		reportReasonsConfigs = reportReasonsConfigDAO.getReportReasonsConfiglistBytype(Short.valueOf(type));
		
		List<ReportErrorInfo> reportErrorInfoList = new ArrayList<ReportErrorInfo>();
		ReportErrorInfo reportErrorInfo = null;
		
		for (int i = 0; i < reportReasonsConfigs.size(); i++) {
			reportErrorInfo = new ReportErrorInfo();
			reportErrorInfo.setId(String.valueOf(reportReasonsConfigs.get(i).getReasonId()));
			reportErrorInfo.setError(reportReasonsConfigs.get(i).getName());
			reportErrorInfoList.add(reportErrorInfo);
			reportErrorInfo = null;
		}
		
		return reportErrorInfoList;
	}

	public List<ReportReasonsConfig> getReportReasonsConfigs() {
		return reportReasonsConfigs;
	}

	public void setReportReasonsConfigs(
			List<ReportReasonsConfig> reportReasonsConfigs) {
		this.reportReasonsConfigs = reportReasonsConfigs;
	}

	@Override
	public int saveReportError(ReportErrorReq reportErrorReq) {
		//报错或举报对象类型 0:兴趣圈 1:卡信息 2:门店信息 3:用户
		ReportInfo reportInfo = new ReportInfo();
		reportInfo.setReportId(Integer.valueOf(reportErrorReq.getToid()));
		reportInfo.setReportType(Integer.valueOf(reportErrorReq.getType()));
//		reportInfo.setReasonId(Short.valueOf(reportErrorReq.getReasonid()));
		reportInfo.setDescription(reportErrorReq.getContent());
		reportInfo.setUserId(Integer.valueOf(reportErrorReq.getUserid()));
		reportInfo.setCreateTime(System.currentTimeMillis());
		reportInfo.setReason(reportErrorReq.getReason());
		reportInfo.setStatus((short)0);
		return reportInfoDAO.saveReportInfo(reportInfo);

		
	}


}
